

import java.io.*;
import java.net.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Client  {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        Socket mysocket=null;
        DataInputStream in=null;
        DataOutputStream out=null;
        ObjectOutputStream outObj=null;
        ObjectInputStream inObj=null;
        Thread readData;
        Read read=null;
        try{  mysocket=new Socket();
            read = new Read();
            readData = new Thread(read);
            System.out.print("输入服务器的IP:");
            String IP = scanner.nextLine();
            System.out.print("输入端口号:");
            int port = scanner.nextInt();
            if(mysocket.isConnected()){}
            else{
                InetAddress address=InetAddress.getByName(IP);
                InetSocketAddress socketAddress=new InetSocketAddress(address,port);
                mysocket.connect(socketAddress);
                //in =new DataInputStream(mysocket.getInputStream());
                //out = new DataOutputStream(mysocket.getOutputStream());
                outObj=new ObjectOutputStream(mysocket.getOutputStream());
                inObj=new ObjectInputStream(mysocket.getInputStream());
                //read.setDataInputStream(in);
                read.setObjectInputStream(inObj);
                readData.start();
            }
        }
        catch(Exception e) {
            System.out.println("服务器已断开"+e);
        }
        //System.out.print("输入人员的名字：放弃请输入#):");
//        Person p=new Person();
//        p.setName("张三");
//        System.out.println("准备发送人员信息："+p);
//        try {
//            outObj.writeObject(p);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        System.out.println("发送完毕："+p);
        while(scanner.hasNext()) {
            double radius=0;
            Person p=new Person();
            try {
                //radius = scanner.nextDouble();
                String name=scanner.nextLine();
                System.out.println("你输入的名字叫："+name);
                p.setName(name);
            }
            catch(InputMismatchException exp){
                System.exit(0);
            }
            try {
                //out.writeDouble(radius);
                //out.writeUTF(p.toString().getBytes());
                
                System.out.println("准备发送人员信息："+p);
                outObj.writeObject(p);
                System.out.println("发送完毕："+p);
            }
            catch(Exception e) {}
        }
    }
}